package com.ruoyi.web.controller.youxuan;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YouxuanPreferential;
import com.ruoyi.system.service.IYouxuanPreferentialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠管理Controller
 * 
 * @author admin
 * @date 2021-01-12
 */
@RestController
@RequestMapping("/youxuan/preferential")
public class YouxuanPreferentialController extends BaseController
{
    @Autowired
    private IYouxuanPreferentialService youxuanPreferentialService;

    /**
     * 查询优惠管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:preferential:list')")
    @GetMapping("/list")
    public TableDataInfo list(YouxuanPreferential youxuanPreferential)
    {
        startPage();
        List<YouxuanPreferential> list = youxuanPreferentialService.selectYouxuanPreferentialList(youxuanPreferential);
        return getDataTable(list);
    }

    /**
     * 导出优惠管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:preferential:export')")
    @Log(title = "优惠管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YouxuanPreferential youxuanPreferential)
    {
        List<YouxuanPreferential> list = youxuanPreferentialService.selectYouxuanPreferentialList(youxuanPreferential);
        ExcelUtil<YouxuanPreferential> util = new ExcelUtil<YouxuanPreferential>(YouxuanPreferential.class);
        return util.exportExcel(list, "preferential");
    }

    /**
     * 获取优惠管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('youxuan:preferential:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(youxuanPreferentialService.selectYouxuanPreferentialById(id));
    }

    /**
     * 新增优惠管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:preferential:add')")
    @Log(title = "优惠管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YouxuanPreferential youxuanPreferential)
    {
        return toAjax(youxuanPreferentialService.insertYouxuanPreferential(youxuanPreferential));
    }

    /**
     * 修改优惠管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:preferential:edit')")
    @Log(title = "优惠管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YouxuanPreferential youxuanPreferential)
    {
        return toAjax(youxuanPreferentialService.updateYouxuanPreferential(youxuanPreferential));
    }

    /**
     * 删除优惠管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:preferential:remove')")
    @Log(title = "优惠管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(youxuanPreferentialService.deleteYouxuanPreferentialByIds(ids));
    }
}
